<template>
  <div class="mui-numbox" data-numbox-min="0">
    <button class="mui-btn mui-numbox-btn-minus" type="button">-</button>
    <input class="mui-numbox-input" type="number" value="1" @change="countChanged" ref="num">
    <button class="mui-btn mui-numbox-btn-plus" type="button">+</button>
  </div>
</template>
<script>
import mui from "../../lib/mui/js/mui.min.js";

export default {
  props: ["maxNum"],
  // 在渲染出数字选择框的时候,可能maxNum还未传来,因为maxNum是由父组件发送请求后得到的信息
  // 所以用watch监测,发生改变的时候,就为选择框添加一个最大值
  watch: {
    maxNum: function(newVal, oldVal) {
      mui(".mui-numbox")
        .numbox()
        .setOption("max", newVal);
    }
  },
  methods: {
    countChanged() {
      this.$emit("getCount", this.$refs.num.value);
    }
  }
};
</script>
<style lang="scss" scoped>
</style>
